package com.sjp.demo.rpc.provider;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RpcProxyServer {

    private ExecutorService executorService = Executors.newCachedThreadPool();
    private Map<String, Object> serviceMap;

    public void publish(int port, Map<String, Object> serviceMap) {
        this.serviceMap = serviceMap;

        try (ServerSocket serverSocket = new ServerSocket(port)) {
            while (true) {//不断接收请求
                System.out.println("等待请求……");
                Socket accept = serverSocket.accept();
                executorService.execute(new ProcessorHandler(accept, serviceMap));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
